package com.leyou.auth.web;


import com.leyou.auth.dto.AliOssSignatureDTO;
import com.leyou.auth.service.AliAuthService;
import com.leyou.common.constants.RedisConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * <h3>leyou-project</h3>
 * <p></p>
 *
 * @author : hhw
 * @date : 2020-05-24 19:56
 **/
@RestController
@RequestMapping("/ali")
public class AliAuthController {


    @Autowired
    private StringRedisTemplate stringRedisTemplate;
   @Autowired
    private AliAuthService aliAuthService;

    /**
     *@描述  服务器签名返回给前端
     *@参数  []
     *@返回值  org.springframework.http.ResponseEntity<com.leyou.auth.dto.AliOssSignatureDTO>
     *@创建人  hhw
     *@创建时间  2020/5/24
     *@修改人和其它信息
     */
    @GetMapping("/oss/signature")
    public ResponseEntity<AliOssSignatureDTO> getSignature(){
        AliOssSignatureDTO signatureDTO = aliAuthService.getSignature();
        return ResponseEntity.ok(signatureDTO);
    }

    @PostMapping("/image/url")
    public ResponseEntity<Void> getCallback(@RequestParam("imageUrl") String imageUrl){
        stringRedisTemplate.opsForSet().add(RedisConstants.BRAND_PIC_RESOURCE, imageUrl);
        return ResponseEntity.status(HttpStatus.OK).build();
    }



}
